
#include <bits/stdc++.h>
#define int long long
using namespace std;
typedef pair< int,int > pii;

int inline read(){
    int x = 0,f = 1;char c = getchar();
    while(!isdigit(c)){if(c == '-')f = -1;c=getchar();}
    while(isdigit(c)){x = x * 10 + c - '0';c=getchar();}
    return x*f;
}

struct node{
    int wz,sd,jsd;
}a[100005];
int cs[100005];

signed main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    int T = read();
    while(T--){
        int n = read(),m = read(),l = read(),v = read();
        for(int i = 1;i <= n;i++)
            a[i].wz = read(),
            a[i].sd = read(),
            a[i].jsd = read();
        for(int i = 1;i <= m;i++)cs[i]=read();

        cout << rand()%n << " " <<rand()%m;
    }
    return 0;
}
